<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * 用户表
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name')->unique();
            $table->tinyInteger('type')->default(2)
                ->comment('用户类型，1：管理员，2：普通用户，登录管理后台需要类型为1，具体权限有用户角色决定');
            $table->bigInteger('rank_point')->default(0)->comment('用户等级积分, 1元等于1积分，向下取整');
            $table->bigInteger('pay_point')->default(0)
                ->comment('用户消费积分，可用于兑换商品，或者积分商城');
            $table->string('email')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('phone')->nullable();
            $table->timestamp('phone_verified_at')->nullable();
            $table->string('password');
            $table->string('token')->comment('用户登录后保存的token，用户异步验证');
            $table->string('last_ip')->nullable()->comment('最后一次的登录IP');
            $table->bigInteger('last_time')->nullable()->comment('最后一次的登录时间');
            $table->string('m_openid')->nullable()->comment('微信小程序的openid');
            $table->string('g_openid')->nullable()->comment('微信公众号的openid');
            $table->string('union_id')->nullable()->comment('微信平台的的union');
            $table->string('nickname')->nullable()->comment('用户昵称');
            $table->string('avatar')->nullable()->comment('用户头像，保存路径为完整的url');
            $table->tinyInteger('sex')->default(0)->comment('0：未知，1：男，2：女');
            $table->string('country')->nullable()->comment('用户所在国家');
            $table->string('province')->nullable()->comment('用户所在省份');
            $table->string('city')->nullable()->comment('用户所在城市');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
